package com.erp.job;

import com.erp.controller.UserController;
import com.erp.dto.TokenData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;

@Slf4j
@Service
public class TokenCheckJob {

    @Scheduled(cron = "*/10 * * * * ?")
    public void checkToken() {
        log.info("===========check token============= ");
        Map<String, TokenData> map = UserController.map;
        Set<String> set = map.keySet();
        for (String key : set) {
            TokenData tokenData = map.get(key);
            long time = System.currentTimeMillis() - tokenData.getLastAccessTime().getTime();
            if (time > 1000 * 60 * 60) {
                log.info("token 过期，key:{}", key);
                map.remove(key);
            }
        }
    }
}
